package com.gupao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gupao.entity.User;
import com.gupao.model.ResultMap;
import com.gupao.service.UserService;
import com.gupao.shiro.JWTUtil;

@RestController
@RequestMapping("/boss")
public class BossController {
//	private static final Logger log = LoggerFactory.getLogger(BossController.class);
	
	@Autowired
	private UserService userService;
    private ResultMap resultMap=new ResultMap();
	
	@GetMapping("/app/add/{id}")
	public String addApp(@PathVariable String id) {
		return "新增商户："+id+"成功！";
	}
	
	@PostMapping("/login")
    public ResultMap login(@RequestParam("username") String username,
                           @RequestParam("password") String password) {
        User user = userService.selectByUsername(username);
        if (user == null) {
            return resultMap.fail().code(401).message("用户名错误");
        } else if (!user.getPassword().equals(password)) {
            return resultMap.fail().code(401).message("密码错误");
        } else {
            return resultMap.success().code(200).message(JWTUtil.createToken(username));
        }
    }
	
	@PostMapping("/app/update")
	public ResultMap updateApp(@RequestParam("username") String username) {
		return resultMap.success().code(200).message("修改商户："+username+"成功！");
	}
	
}
